<template>
<div class=''>
<el-dialog title="订单结算" :visible.sync="dialogTableVisible">
				<el-form :model="lscljzf">
                    <el-form-item label="支付方式">
						<el-radio-group v-model="lscljzf.zffs">
							<el-radio :label="1">现金支付</el-radio>
							<el-radio :label="0">余额支付</el-radio>
                            <el-radio :label="2">支付宝</el-radio>
						</el-radio-group>
					</el-form-item>

                    <el-row :gutter="12">
                     <el-col :span="8">
					<el-input  v-model="lscljzf.wxdd" size="small " :readonly="rdy">
                        <template slot="prepend">
                            <div style="color: #000;">维修单号</div>
                            </template>
                    </el-input>
                     </el-col>
                    <el-col :span="8">
                    <el-input  v-model="lscljzf.syy" size="small " :readonly="rdy">
                        <template slot="prepend">
                            <div style="color: #000;">收银人员</div>
                            </template>
                    </el-input>
                    </el-col>
                    
					</el-row>
                <br>
                    <el-row :gutter="12">
                     <el-col :span="8">
					<el-input  v-model="lscljzf.yh.username" size="small " :readonly="rdy">
                        <template slot="prepend">
                            <div style="color: #000;">客户名称</div>
                            </template>
                    </el-input>
                     </el-col>
                    <el-col :span="8">
                    <el-input  v-model="lscljzf.yh.uamount" size="small " :readonly="rdy">
                        <template slot="prepend">
                            <div style="color: #000;">客户余额</div>
                            </template>
                    </el-input>
                    </el-col>
					</el-row>
                     <br>
                    <el-row :gutter="12">
                     <el-col :span="8">
					<el-input  v-model="lscljzf.yprice" size="small " :readonly="rdy">
                        <template slot="prepend">
                            <div style="color: #000;">应付金额</div>
                            </template>
                    </el-input>
                     </el-col>
                    <el-col :span="8">
                    <el-input  v-model="lscljzf.sprice" size="small " :readonly="rdy">
                        <template slot="prepend">
                            <div style="color: #000;">实付金额</div>
                            </template>
                    </el-input>
                    </el-col>
					</el-row>
                     <br>
                    <el-row :gutter="12">
                     <el-col :span="8">
					<el-input  v-model="lscljzf.zk" size="small " :readonly="rdy">
                        <template slot="prepend">
                            <div style="color: #000;">优惠折扣</div>
                            </template>
                    </el-input>
                     </el-col>
					</el-row>

				</el-form>
				<div slot="footer" class="dialog-footer">
					<el-button @click="dialogTableVisible = false">取 消</el-button>
					<el-button type="primary" @click="qdzf()">确 定</el-button>
				</div>
			</el-dialog>

     <el-row :gutter="10">
         <el-col :span="4">
    <el-page-header @back="goBack" content="订单详情"></el-page-header>
    
         </el-col>
        <el-col :span="2" v-if="list.servicestatename!='维修完毕'"> <el-button type="success" icon="el-icon-circle-check" size="small " @click="ljjs()">立即结算</el-button></el-col>
        <el-col :span="1"><el-button type="primary" icon="el-icon-printer" size="small " @click="wzdy()">打印</el-button></el-col>
     </el-row>
<div id="dynr">
    <el-row :gutter="10">
   <el-col :span="4">
          <h2>--- {{list.serviceType}}</h2>
          </el-col>
    </el-row>
    <el-row :gutter="10">
         <el-col :span="5">
             <el-input  v-model="list.repairbillno" size="small " :readonly="rdy">
        <template slot="prepend" >
             <div style="color: #000;">维修单号</div>
        </template>
  </el-input></el-col>
  <el-col :span="5"><el-input  v-model="list.ulicense" size="small " :readonly="rdy">
    <template slot="prepend">
        <div style="color: #000;">车牌号</div>
        </template>
  </el-input></el-col>
    </el-row>
    <br>
    <el-row :gutter="10">
        
         <el-col :span="5">
             <el-input  v-model="list.redriver" size="small " :readonly="rdy">
        <template slot="prepend" >
             <div style="color: #000;">驾驶员</div>
        </template>
  </el-input></el-col>
  <el-col :span="5"><el-input  v-model="list.redriverphone" size="small " :readonly="rdy">
    <template slot="prepend">
        <div style="color: #000;">驾驶员电话</div>
        </template>
  </el-input></el-col>
</el-row>
<br>
   
    <el-row :gutter="10">
        
         <el-col :span="5" >
             <div class="" style="text-align:left;font-size:17px;margin-bottom:8px">业务类别</div>
             <el-input  v-model="list.sename" size="small " :readonly="rdy">
        
        </el-input>
        </el-col>
  
         <el-col :span="5">
             <div class="" style="text-align:left;font-size:17px;margin-bottom:8px">施工班次</div>
             <el-input  v-model="list.shiftsname" size="small " :readonly="rdy">
        </el-input>
        </el-col>

         <el-col :span="5">
             <div class="" style="text-align:left;font-size:17px;margin-bottom:8px">结算方式</div>
             <el-input  v-model="list.clearingformname" size="small " :readonly="rdy">
        </el-input>
        </el-col>
</el-row>
<br>
 <el-row :gutter="10">
        
         <el-col :span="5" >
             <div class="" style="text-align:left;font-size:17px;margin-bottom:8px" >进厂油量</div>
             <el-input  v-model="list.oilmassname" size="small " :readonly="rdy">
        </el-input>
        </el-col>
 </el-row>
<br>
  <el-row :gutter="10">
        
         <el-col :span="5" >
             <div class="" style="text-align:left;font-size:17px;margin-bottom:8px">接待备注</div>
             <el-input type="textarea" v-model="list.receptionnote" :readonly="rdy">
        </el-input>
        </el-col>
         <el-col :span="5" >
             <div class="" style="text-align:left;font-size:17px;margin-bottom:8px">报修陈述</div>
             <el-input type="textarea" v-model="list.statement" :readonly="rdy">
        </el-input>
        </el-col>
 </el-row>
  <br>
 <el-row :gutter="10">
   <el-col :span="4">
          <h3>--- 操作菜单</h3>
          </el-col>
    </el-row>
   
<template>
  <el-tabs v-model="activeName" type="card" @tab-click="handleClick" style="width:980px">
    <el-tab-pane label="项目详情" name="second">
        <template>
            <el-table
                :data="lscql"
                style="width: 100%">
                <el-table-column
                prop="rbprojectid"
                label="项目编号"
                width="180"></el-table-column>
                <el-table-column
                prop="rbprojectsl"
                label="数量"
                width="180"> </el-table-column>
                <el-table-column
                prop="yprice"
                label="原价"> </el-table-column>
                <el-table-column
                prop="yprices"
                label="优惠价"
                width="180"></el-table-column>
                <el-table-column
                prop="rbprojectms"
                label="故障描述"
                width="180"> </el-table-column>
                <el-table-column
                prop="rbprojectyy"
                label="故障原因"></el-table-column>
                 <el-table-column
                prop="nocharge"
                label="免单原因"></el-table-column>   
            </el-table>
        </template>
    </el-tab-pane>
    <el-tab-pane label="附加项目" name="third">
         <template>
            <el-table
                :data="lscse"
                style="width: 100%">
                <el-table-column
                prop="subjoinitemname"
                label="项目名称"
                width="180"></el-table-column>
                <el-table-column
                prop="subjoinprice"
                label="项目价格"
                width="180"> </el-table-column>
                 <el-table-column
                prop="artisansid"
                label="维修小组"
                width="180"> </el-table-column>
                <el-table-column
                prop="mnpricetypeid"
                label="付款类型"> 
                </el-table-column>
                <el-table-column
                prop="remark"
                label="备注"
                width="180"> </el-table-column>
                 
            </el-table>
        </template>
    </el-tab-pane>
    <el-tab-pane label="金额估算" name="fourth">
         <template>
            <el-table
                :data="lscprice"
                style="width: 100%">
                <el-table-column
                prop="atime"
                label="人工费用"
                width="180">
                </el-table-column>
                <el-table-column
                prop="yjg"
                label="原价格"
                width="180"> 
                </el-table-column>
                 <el-table-column
                prop="yhjg"
                label="优惠价格"
                width="180"> 
                </el-table-column>
                <el-table-column
                prop="yjg"
                label="积分"> 
                <template>
                    {{lscjf}}
                </template>
                </el-table-column>
            </el-table>
        </template>
    </el-tab-pane>
  </el-tabs>
</template>


</div>
</div>
</template>

<script src="print.js"></script>
<script>
import print from 'print-js'
export default {
data() {
//这里存放数据
return {
    number:"",
    list:{},
    rid:"",
    rdy:true,
    index:"",
    activeName: '',
    lscql:[],
    lscse:[],
    lscprice:[],
    lscjf:"",
    dialogTableVisible: false,
    lscljzf:{
        zffs:0,
        wxdd:"",
        syy:"青霄",
        yprice:"",
        sprice:"",
        yh:{},
        zk:""
    },
    ddjsdx:{
        settleid:"0",
        eid:"0",
        repairbillsno:"",
        settletime:"",
        settleintegral:"",
        settlesum:"",
        closeprice:"",
        materialspr:"0",
        manhourpr:"0",
        additionpr:"0",
        itemprice:"0",
        finallyprice:"0",
        rescueprice:"0",
        settletype:"",
    }


};
},
//计算属性
computed: {},
//方法集合
methods: {
    handleClick(tab, event) {
        //console.log(tab, event);
        if(tab.index==0){
           // this.xmxq()
        }else if(tab.index==1){
            
        }else{
           
        }
      },
    goBack() {
        history.back();
      },
     wzdy(){
        print({
            printable:'dynr',
            type:"html",
            scanStyles:true,
            headerStyle:'font-size:25px;font-weight: 300;',
            header:'订单详情',
            documentTitle:"株洲九郎山4s店",
            targetStyle:['*'],
            ignoreElements:['no-print','bc','gb'],
            style: ''
        })
     },
    xmxq(){
        let th =this
        this.$http.get("http://localhost:8080/c/lscrpj/lscql",{
        params:{
            rid:th.rid
        }
        }).then(resp=>{
            th.lscql=resp.data
           // console.log(th.lscql)
        })
    },
    fjxm(){
         let th =this
        this.$http.get("http://localhost:8080/c/lscsvia/qrid",{
        params:{
            rid:th.rid
        }
        }).then(resp=>{
            th.lscse=resp.data
           // console.log(th.lscse)
        })
    },
    jgjs(){
         let th =this
        this.$http.get("http://localhost:8080/c/jsjg/jg",{
        params:{
            rid:th.rid
        }
        }).then(resp=>{
            th.lscprice=resp.data
            th.lscjf=th.lscprice[0].yjg*0.1
            if(th.lscprice[0].yhjg==0){
                th.lscprice[0].yhjg=parseFloat(th.lscprice[0].yjg)+th.lscprice[0].subjoinprice*1
            }else{
            th.lscprice[0].yhjg=parseFloat(th.lscprice[0].yhjg)+th.lscprice[0].subjoinprice*1
            }
            th.lscprice[0].yjg =  parseFloat(th.lscprice[0].yjg)+th.lscprice[0].subjoinprice*1
              
            
          
           // console.log(th.lscprice)
        })
    },
    ljjs() {
		this.dialogTableVisible = true
        this.lscljzf.wxdd=this.rid
        this.lscljzf.yprice=this.lscprice[0].yjg*1+this.lscprice[0].atime*1
        let th =this
        this.$http.get("http://localhost:8080/c/utba/quser",{
        params:{
            rid:th.rid
        }
        }).then(resp=>{
            th.lscljzf.yh=resp.data
            if(th.lscljzf.yh.isvip!=0){
                th.lscljzf.zk=9
                th.lscljzf.sprice=th.lscprice[0].yhjg*1+this.lscprice[0].atime*1
            }else{
                 th.lscljzf.sprice=th.lscprice[0].yjg*1+this.lscprice[0].atime*1
            }
           // console.log(th.lscprice)
        })

	},
    qdzf(){
        let th=this
        if(this.lscljzf.zffs==1){
            
        }else if(this.lscljzf.zffs==0){
            if(this.lscljzf.sprice>this.lscljzf.yh.uamount){
               this.$message.error('余额不足');
               return 
            }else{
                this.lscljzf.yh.uamount-=this.lscljzf.sprice
                //alert(this.lscljzf.yh.uamount)
            }

        }
        this.ddjsdx.repairbillsno=this.rid
         this.lscljzf.yh.uintegral+=this.lscjf*1
         this.ddjsdx.settleintegral=this.lscjf
         this.ddjsdx.settlesum=this.lscljzf.yprice
        this.ddjsdx.closeprice=this.lscljzf.yprice-this.lscljzf.sprice
        this.ddjsdx.finallyprice=this.lscljzf.sprice
        this.ddjsdx.settletype=this.list.serviceType
        this.$http.post("http://localhost:8080/c/lscsett/add",this.ddjsdx).then(resp=>{
            if(resp.data==0){
                this.$message.error('结算更新失败');
            }
        })
        this.$http.put(`http://localhost:8080/c/lscrpill/xg/${th.rid}`
        
        ).then(resp=>{
           if(resp.data==0){
                this.$message.error('订单更新失败');
            }
        // console.log(th.list)
        })
        
         //alert(this.lscljzf.yh.uintegral)
        //更新用户的积分和余额
        this.$http.put("http://localhost:8080/c/user/xg",this.lscljzf.yh).then(resp=>{
            if(resp.data==0){
                this.$message.error('客户更新失败');
            }
        })
        

       if(this.lscljzf.zffs==2){
           this.created();
         location.replace("http://127.0.0.1:8081/zfb/alipay.trade.page.pay.jsp?WIDout_trade_no="+this.rid+"&WIDsubject="+this.rid+"&WIDtotal_amount="+this.lscljzf.sprice+"&WIDbody=")

       }
       this.dialogTableVisible = false
    },
    created () {
  // 调用获取当前日期的方法加四位随机数  赋值表单中的项目编号
  this.number = this.getProjectNum() + Math.floor(Math.random() * 10000)  // 如果是6位或者8位随机数，相应的 *1000000或者 *100000000就行了
   console.info(this.number)
},

	// 获取当前日期的方法
	getProjectNum () {
      const projectTime = new Date() // 当前中国标准时间
      const Year = projectTime.getFullYear() // 获取当前年份 支持IE和火狐浏览器.
      const Month = projectTime.getMonth() + 1 // 获取中国区月份
      const Day = projectTime.getDate() // 获取几号
      var CurrentDate = String(Year) 
      if (Month >= 10) { // 判断月份和几号是否大于10或者小于10
        CurrentDate += Month
      } else {
        CurrentDate += '0' + Month
      }
      if (Day >= 10) {
        CurrentDate += Day
      } else {
        CurrentDate += '0' + Day
      }
      return CurrentDate
    }
},
//挂载完成（可以访问DOM元素）
mounted() {
    let th=this
    console.log(this.$route.params.id)
    this.rid=this.$route.params.id
    this.$http.get("http://localhost:8080/c/rucf/qrxq",{
        params:{
            rid:th.rid
        }
    }).then(resp=>{
        th.list=resp.data
       // console.log(th.list)
    })
    this.xmxq()
    this.fjxm();
     this.jgjs();
},
//监控data中的数据变化
watch: {

}
}
</script>
<style  scoped>
/*@import url(); 引入公共css类*/

</style>